# show hdf5 struct
import h5py

import argparse
import os

def show_hdf5_structure(file_path):
    def print_structure(name, obj):
        indent = '  ' * name.count('/')
        if isinstance(obj, h5py.Dataset):
            print(f"{indent}{name}: Dataset, shape={obj.shape}, dtype={obj.dtype}")
        elif isinstance(obj, h5py.Group):
            print(f"{indent}{name}: Group")

    with h5py.File(file_path, 'r') as f:
        print(f"HDF5 file structure for: {file_path}")
        f.visititems(print_structure)

def main():
    parser = argparse.ArgumentParser(description='Show HDF5 file structure')
    parser.add_argument('--data', type=str, required=True, help='Path to the HDF5 file')
    args = parser.parse_args()

    if not os.path.exists(args.data):
        print(f"Error: File '{args.data}' does not exist.")
        return

    show_hdf5_structure(args.data)

if __name__ == '__main__':
    main()
